
#include <cstdio>

#include "SDL.h"
#include "SDL_image.h"
#include "ddc.h"

static DDC_BoxCollider2D *boxCollider = nullptr;

int main000(int argc, char *argv[]) {
    Dodoco *dodoco = Dodoco::GetDodocoWithInit(800, 600, 60);

    DDC_Scene *scene = dodoco->NewScene("InitScene");

    DDC_BaseSDLTexture *baseTexture = DDC_BaseSDLTexture::LoadFromFile("res/texture.png");

    if (baseTexture == nullptr) {
        printf("Error : %s\n", DDC_ErrGet().c_str());
        return 0;
    }

    std::vector<DDC_SpriteTexture *> stVec({
        DDC_SpriteTexture::CutFromBaseTexture(baseTexture, DDC_Rect {1, 43, 16, 35}),
        DDC_SpriteTexture::CutFromBaseTexture(baseTexture, DDC_Rect {18, 43, 19, 35}),
        DDC_SpriteTexture::CutFromBaseTexture(baseTexture, DDC_Rect {38, 43, 20, 35}),
        DDC_SpriteTexture::CutFromBaseTexture(baseTexture, DDC_Rect {59, 43, 16, 35}),
        DDC_SpriteTexture::CutFromBaseTexture(baseTexture, DDC_Rect {76, 43, 18, 35}),
        DDC_SpriteTexture::CutFromBaseTexture(baseTexture, DDC_Rect {95, 43, 20, 35}),
    });

    DDC_GameObject *go = scene->NewGameObject("Anim");
    DDC_AnimateSpriteRenderer *asr =
        go->AddCompoment<DDC_Sprite2D>()
            ->SetKeepTextureScale(true)
              ->UseSpriteRenderer<DDC_AnimateSpriteRenderer>();
    go->gameObjectRect = DDC_FRect {30, 30, 200, 350};

    DDC_SpriteAnimate *sa = new DDC_SpriteAnimate(200, true);
    sa->SetFrames(stVec);
    int _state = 0;
    asr->AddAnimate(sa, &_state);

    uint32_t colorKey = SDL_MapRGB(dodoco->GetDodocoWindowSurface()->format, 31, 220, 0);
    if (SDL_SetColorKey(dodoco->GetDodocoWindowSurface(), SDL_TRUE, colorKey) < 0) {
        printf("fault to set color key\n");
    }

    dodoco->Run(scene);

freeAll:
    delete baseTexture;
}
